Which of the following correctly declares an array?a)int array[10];b)i...
Because array variable and values need to be declared after the datatype only.
View all questions of this test
Which of the following correctly declares an array?a)int array[10];b)i...
Declaring an Array in C++
Declaring an array in C++ requires specifying the data type of the array elements and the number of elements in the array.
Syntax
The general syntax for declaring an array in C++ is as follows:
data_type array_name[array_size];
- data_type: The data type of the array elements.
- array_name: The name of the array.
- array_size: The number of elements in the array.
Explanation
Option A: int array[10]
- This option correctly declares an array named "array" containing 10 elements of integer data type.
- The data type is specified as "int" and the number of elements is specified as "10".
- Therefore, this option is the correct answer.
Option B: int array
- This option declares a variable named "array" of integer data type.
- However, it does not specify the number of elements in the array.
- Therefore, this option is incorrect.
Option C: array{10}
- This option uses brace initialization syntax to initialize an array with a single element containing the value 10.
- However, it does not declare an array with a specific number of elements.
- Therefore, this option is incorrect.
Option D: array array[10]
- This option declares an array of custom data type named "array" containing 10 elements.
- However, it does not specify the data type of the array elements.
- Therefore, this option is incorrect.